package com.yangcangclub.message.domain;

import com.google.common.collect.Maps;
import com.yangcangclub.commons.exception.ApolloException;
import com.yangcangclub.commons.result.MessageEnum;
import com.yangcangclub.message.base.MesgBaseDomain;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 用户反馈
 */
@Component
public class FeedBack extends MesgBaseDomain{


    /**
     * 新增反馈
     */
    public boolean addFeedback(int userId,String content,String contact){
        Map<String,Object> map= Maps.newHashMap();
        map.put("user_id",userId);
        map.put("content",content);
        map.put("contact",contact);
        return 1 == super.getMasterJdbc().insert("message.MesgMapper.insertFeedBack", map);

    }

    /**
     * 获取用户信息List
     */
    public  List<Map<String, Object>> getList(int start, int pageSize, String orderBy){
        if(start<0||pageSize>200||pageSize<0){
            throw new ApolloException(MessageEnum.PARMA_RANGE_ERROR);
        }

        Map<String,Object> map= Maps.newHashMap();
        map.put("start",start);
        map.put("pageSize",pageSize);
        map.put("orderBy",orderBy);
        List<Map<String, Object>> list= super.getSlaveJdbc().selectList("message.MesgMapper.selectFeedbackList", map);

        return list;
    }


    /**
     * 获取总数量
     */
    public int getFeedbackCount(){
        return super.getSlaveJdbc().selectOne("message.MesgMapper.selectFeedbackCount");
    }



}
